module.exports = {
  apps: [
    {
      name: 'text-tags-backend',
      script: 'dist/main.js',
      cwd: process.env.PWD || '/www/wwwroot/server/text-tags-backend',
      instances: 1, // 单实例，如需多实例可设置为 'max' 或具体数字
      exec_mode: 'fork', // 或 'cluster' 模式用于多实例
      
      // 环境变量
      env: {
        NODE_ENV: 'production',
        PORT: 3000,
        // 数据库配置
        DB_HOST: '49.51.193.79',
        DB_PORT: 3306,
        DB_USERNAME: 'prompt',
        DB_PASSWORD: '42SSH3Br6AH2RsJ2',
        DB_DATABASE: 'prompt',
        // CORS配置
        CORS_ORIGIN: 'http://localhost:5173',
        // Coze API配置
        COZE_TOKEN: 'pat_TcXC0WRdPt6Vo9gbiqIBoxHdElvLsFzcp7eXY3lY6j3mZ3jC0gldZKjpC30BpHLx',
        COZE_WORKFLOW_ID: '7566577660957950015',
        COZE_SPACE_ID: '7380640004466851877',
        COZE_WORKFLOW_ADD_ID: '7566577660957950015',
        COZE_WORKFLOW_LIST_ID: '7567003122771656746'
      },
      
      // 生产环境配置
      env_production: {
        NODE_ENV: 'production',
        PORT: 3000,
        DB_HOST: '49.51.193.79',
        DB_PORT: 3306,
        DB_USERNAME: 'prompt',
        DB_PASSWORD: '42SSH3Br6AH2RsJ2',
        DB_DATABASE: 'prompt',
        CORS_ORIGIN: 'http://localhost:5173',
        // Coze API配置
        COZE_TOKEN: 'pat_TcXC0WRdPt6Vo9gbiqIBoxHdElvLsFzcp7eXY3lY6j3mZ3jC0gldZKjpC30BpHLx',
        COZE_WORKFLOW_ID: '7566577660957950015',
        COZE_SPACE_ID: '7380640004466851877',
        COZE_WORKFLOW_ADD_ID: '7566577660957950015',
        COZE_WORKFLOW_LIST_ID: '7567003122771656746'
      },
      
      // 开发环境配置
      env_development: {
        NODE_ENV: 'development',
        PORT: 3000,
        DB_HOST: '49.51.193.79',
        DB_PORT: 3306,
        DB_USERNAME: 'prompt',
        DB_PASSWORD: '42SSH3Br6AH2RsJ2',
        DB_DATABASE: 'prompt',
        CORS_ORIGIN: 'http://localhost:5173',
        // Coze API配置
        COZE_TOKEN: 'pat_TcXC0WRdPt6Vo9gbiqIBoxHdElvLsFzcp7eXY3lY6j3mZ3jC0gldZKjpC30BpHLx',
        COZE_WORKFLOW_ID: '7566577660957950015',
        COZE_SPACE_ID: '7380640004466851877',
        COZE_WORKFLOW_ADD_ID: '7566577660957950015',
        COZE_WORKFLOW_LIST_ID: '7567003122771656746'
      },
      
      // 日志配置
      log_file: './logs/combined.log',
      out_file: './logs/out.log',
      error_file: './logs/error.log',
      log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
      
      // 进程管理
      autorestart: true,
      watch: false, // 生产环境建议关闭文件监控
      max_memory_restart: '1G',
      
      // 健康检查
      health_check_grace_period: 3000,
      
      // 启动配置
      min_uptime: '10s',
      max_restarts: 10,
      
      // 其他配置
      kill_timeout: 5000,
      listen_timeout: 3000,
      wait_ready: true,
    }
  ],
  
  // 部署配置（可选）
  deploy: {
    production: {
      user: 'node',
      host: 'your-server.com',
      ref: 'origin/main',
      repo: 'git@github.com:username/repo.git',
      path: '/var/www/production',
      'pre-deploy-local': '',
      'post-deploy': 'npm install && npm run build && pm2 reload ecosystem.config.js --env production',
      'pre-setup': ''
    }
  }
};

